#include <iostream>
#include <string>
using namespace std;
int min(int a,int b){
    if(a<b){
	return a;
    }else{
	return b;
    }
}
int main(){
    string d1;
    string d2;
    string m1;
    string m2;
    cin>>d1;
    cin>>d2;
    cin>>m1;
    cin>>m2;
    int date;
    int hour;
    int minute;
    int len1=min(d1.length(),d2.length());
    int len2=min(m1.length(),m2.length());
    int type=0;
    for(int i=0;i<len1;i++){
	if(type==0){
	    if((d1[i]==d2[i])&&(d1[i]>='A'&&d1[i]<='G')){
		date=d1[i]-'A'+1;
		type=1;
	    }
	}else if(type==1){
	    if(d1[i]==d2[i]){
		if(d1[i]>='0'&&d1[i]<='9'){
		    hour=d1[i]-'0';
		    break;
		}else if(d1[i]>='A'&&d1[i]<='N'){
		    hour=d1[i]-'A'+10;
		    break;
		}
	    }
	}
    }
    for(int i=0;i<len2;i++){
	if((m1[i]>='a'&&m1[i]<='z')||(m1[i]>='A'&&m1[i]<='Z')){
	if(m1[i]==m2[i]){
	    minute=i;
	    break;
	}
	}
    }
    switch(date){
    case 1:
	cout<<"MON ";
	break;
    case 2:
	cout<<"TUE ";
	break;
    case 3:
	cout<<"WED ";
	break;
    case 4:
	cout<<"THU ";
	break;
    case 5:
	cout<<"FRI ";
	break;
    case 6:
	cout<<"SAT ";
	break;
    case 7:
	cout<<"SUN ";
	break;
    }
    if(hour<10){
	cout<<"0";
    }
    cout<<hour<<":";
    if(minute<10){
	cout<<"0";
    }
    cout<<minute<<endl;
}
